﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Text;

namespace AllNations.Framework
{
    public class BloggerConfiguration
    {
        public int PageSize { get; set; }

        internal void Deserialize(string sSettings)
        {
            if (!string.IsNullOrEmpty(sSettings))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(sSettings);
                XmlElement elem = doc.DocumentElement;
                var nodePageSize = elem.SelectSingleNode("PageSize");
                if (nodePageSize != null)
                    PageSize = int.Parse(nodePageSize.InnerText);
                else
                    PageSize = 5;
            }
            else
            {
                // default settings
                PageSize = 5;
            }
        }

        internal string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb);
            writer.WriteStartDocument();
            writer.WriteStartElement("BloggerSettings");
            writer.WriteElementString("PageSize", PageSize.ToString());
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            return sb.ToString();
        }
    }
}